<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<!-- Mirrored from www.wolfssl.com/wolfSSL/Docs-wolfssl-manual-18-1-wolfcrypt-api-aes.html by HTTrack Website Copier/3.x [XR&CO'2014], Tue, 17 Jan 2017 13:36:31 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8" /><!-- /Added by HTTrack -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="Generator" content="iWeb 3.0.4"/>
<meta name="iWeb-Build" content="local-build-20170103"/>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<meta name="viewport" content="width=770"/>
<title>wolfSSL - Docs | wolfCrypt Manual - Chapter 18.1 (AES)</title>
<link rel="stylesheet" type="text/css" media="screen,print" href="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/Docs-wolfssl-manual-18-1-wolfcrypt-api-aes.css"/>
<!--[if lt IE 8]><link rel='stylesheet' type='text/css' media='screen,print' href='Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/Docs-wolfssl-manual-18-1-wolfcrypt-api-aesIE.css'/><![endif]-->
<!--[if gte IE 8]><link rel='stylesheet' type='text/css' media='screen,print' href='Media/IE8.css'/><![endif]-->
<script type="text/javascript" src="Scripts/iWebSite.js"></script>
<script type="text/javascript" src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/Docs-wolfssl-manual-18-1-wolfcrypt-api-aes.js"></script>
<meta name="description" content="wolfSSL - Docs | wolfCrypt Manual - Chapter 18.1 (AES)"/><meta name="keywords" content="embedded ssl, ssl library, embedded security, openssl alternative, ssl api, ssl, tls, cyassl, openssl replacement, openssl api, ssl functions, small openssl, smart grid, connected home, ecc, lightweight ssl, suite b, encryption security software, ssl inspection"/><meta name="robots" content="follow,index"/> <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','../../www.google-analytics.com/analytics.js','ga');ga('create','UA-64826966-1','auto');ga('send','pageview');</script>
 
<script>//<![CDATA[
window.zEmbed||function(e,t){var n,o,d,i,s,a=[],r=document.createElement("iframe");window.zEmbed=function(){a.push(arguments)},window.zE=window.zE||window.zEmbed,r.src="javascript:false",r.title="",r.role="presentation",(r.frameElement||r).style.cssText="display: none",d=document.getElementsByTagName("script"),d=d[d.length-1],d.parentNode.insertBefore(r,d),i=r.contentWindow,s=i.document;try{o=s}catch(c){n=document.domain,r.src='javascript:var d=document.open();d.domain="'+n+'";void(0);',o=s}o.open()._l=function(){var o=this.createElement("script");n&&(this.domain=n),o.id="js-iframe-async",o.src=e,this.t=+new Date,this.zendeskHost=t,this.zEQueue=a,this.body.appendChild(o)},o.write('<body onload="document._l();">'),o.close()}("../../assets.zendesk.com/embeddable_framework/main.js","wolfssl.zendesk.com");
//]]></script>
  </head>
<body style="background: rgb(255, 255, 255); margin: 0pt; " onload="onPageLoad();">
<div style="text-align: center; ">
<div style="margin-bottom: 20px; margin-left: auto; margin-right: auto; margin-top: 20px; overflow: hidden; position: relative; word-wrap: break-word;  background: rgb(255, 255, 255); text-align: left; width: 770px; " id="body_content">
<div style="float: left; margin-left: 0px; position: relative; width: 770px; z-index: 0; " id="nav_layer">
<div style="height: 0px; line-height: 0px; " class="bumper"> </div>
<div style="clear: both; height: 0px; line-height: 0px; " class="spacer"> </div>
</div>
<div style="float: left; height: 0px; line-height: 0px; margin-left: 0px; position: relative; width: 770px; z-index: 10; " id="header_layer">
<div style="height: 0px; line-height: 0px; " class="bumper"> </div>
</div>
<div style="margin-left: 0px; position: relative; width: 770px; z-index: 5; " id="body_layer">
<div style="height: 0px; line-height: 0px; " class="bumper"> </div>
<div id="id1" style="height: 38px; left: 375px; position: absolute; top: 157px; width: 361px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_361_38" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style">wolfSSL Manual</p>
</div>
</div>
</div>
<div id="id2" style="height: 24px; left: 193px; position: absolute; top: 122px; width: 268px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_268_24" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_1"><a class="class1" title="Docs.html" href="Docs.html">Docs</a> <span class="style">-&gt;</span> <span class="style_1">wolfSSL Manual</span></p>
</div>
</div>
</div>
<div style="height: 1px; width: 698px;  height: 1px; left: 37px; position: absolute; top: 220px; width: 698px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 698px; ">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_1.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 698px; "/>
</div>
</div>
<div style="height: 37px; width: 545px;  height: 37px; left: 191px; position: absolute; top: 80px; width: 545px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 545px; ">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_2.png" alt="" style="height: 37px; left: 0px; position: absolute; top: 0px; width: 545px; "/>
</div>
</div>
<div id="id3" style="height: 25px; left: 200px; position: absolute; top: 84px; width: 43px; z-index: 1; " class="style_SkipStroke_1 shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_43_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_2"><a class="class2" title="Home.html" href="Home.html">Home</a></p>
</div>
</div>
</div>
<div id="id4" style="height: 25px; left: 365px; position: absolute; top: 84px; width: 72px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_72_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_3"><a class="class3" title="https://wolfssl.com/wolfSSL/download/downloadForm.php" href="https://wolfssl.com/wolfSSL/download/downloadForm.php">Download</a></p>
</div>
</div>
</div>
<div id="id5" style="height: 25px; left: 439px; position: absolute; top: 84px; width: 59px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_59_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_3"><a class="class4" title="License.html" href="License.html">License</a></p>
</div>
</div>
</div>
<div id="id6" style="height: 25px; left: 499px; position: absolute; top: 84px; width: 44px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_44_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_3"><a class="class5" title="Blog/Blog.html" href="Blog/Blog.html">Blog</a></p>
</div>
</div>
</div>
<div id="id7" style="height: 25px; left: 589px; position: absolute; top: 84px; width: 80px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_80_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_3"><a class="class6" title="Community.html" href="Community.html">Community</a></p>
</div>
</div>
</div>
<div style="height: 36px; width: 1px;  height: 36px; left: 245px; position: absolute; top: 81px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_3.png" alt="" style="height: 36px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div style="height: 37px; width: 1px;  height: 37px; left: 296px; position: absolute; top: 80px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_4.png" alt="" style="height: 37px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div style="height: 36px; width: 1px;  height: 36px; left: 363px; position: absolute; top: 81px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_5.png" alt="" style="height: 36px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div style="height: 36px; width: 1px;  height: 36px; left: 438px; position: absolute; top: 81px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_6.png" alt="" style="height: 36px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div style="height: 37px; width: 1px;  height: 37px; left: 498px; position: absolute; top: 80px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_7.png" alt="" style="height: 37px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div style="height: 37px; width: 1px;  height: 37px; left: 589px; position: absolute; top: 80px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_8.png" alt="" style="height: 37px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div id="id8" style="height: 25px; left: 671px; position: absolute; top: 84px; width: 61px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_61_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_3"><a class="class7" title="Contact.html" href="Contact.html">Contact</a></p>
</div>
</div>
</div>
<div id="id9" style="height: 25px; left: 249px; position: absolute; top: 84px; width: 44px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_44_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_2"><a class="class8" title="About.html" href="About.html">About</a></p>
</div>
</div>
</div>
<div style="height: 36px; width: 1px;  height: 36px; left: 670px; position: absolute; top: 81px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_9.png" alt="" style="height: 36px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div id="id10" style="height: 25px; left: 298px; position: absolute; top: 84px; width: 63px; z-index: 1; " class="style_SkipStroke_1 shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_63_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_3"><a class="class9" title="Products.html" href="Products.html">Products</a></p>
</div>
</div>
</div>
<div id="id11" style="height: 25px; left: 549px; position: absolute; top: 84px; width: 41px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_41_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_2"><a class="class10" title="Docs.html" href="Docs.html">Docs</a></p>
</div>
</div>
</div>
<div style="height: 37px; width: 1px;  height: 37px; left: 545px; position: absolute; top: 80px; width: 0px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 0px; ">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_10.png" alt="" style="height: 37px; left: 0px; position: absolute; top: 0px; width: 1px; "/>
</div>
</div>
<div id="id12" style="height: 27px; left: 634px; position: absolute; top: 224px; width: 102px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_102_27" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_4"><a class="class11" title="Docs-wolfssl-manual-18-2-wolfcrypt-api-arc4.html" href="Docs-wolfssl-manual-18-2-wolfcrypt-api-arc4.html">Next Chapter</a></p>
</div>
</div>
</div>
<div id="id13" style="height: 25px; left: 35px; position: absolute; top: 224px; width: 125px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_125_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_5"><a class="class12" title="Docs-wolfssl-manual-18-wolfcrypt-api-reference.html" href="Docs-wolfssl-manual-18-wolfcrypt-api-reference.html">Previous Chapter</a></p>
</div>
</div>
</div>
<div style="height: 22px; width: 22px;  height: 22px; left: 33px; position: absolute; top: 191px; width: 22px; z-index: 1; " class="tinyText style_SkipStroke_2">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/PDF.png" alt="" style="border: none; height: 22px; width: 22px; "/>
</div>
<div id="id14" style="height: 25px; left: 323px; position: absolute; top: 224px; width: 125px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_125_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_6"><a title="Docs-wolfssl-manual-toc.html" href="Docs-wolfssl-manual-toc.html">Table of Contents</a></p>
</div>
</div>
</div>
<div id="id15" style="height: 10112px; left: 35px; position: absolute; top: 281px; width: 701px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_701_10112" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-top: 0pt; " class="paragraph_style_7">Chapter 18: wolfCrypt API Reference<br/></p>
<p class="paragraph_style_7"><br/></p>
<p class="paragraph_style_8">18.1  AES<br/></p>
<p class="paragraph_style_8"><br/></p>
<p class="paragraph_style_9">The functions in this section expose AES (Advanced Encryption Standard) functionality to calling applications.<span class="style_2"><br/></span></p>
<p class="paragraph_style_10"><br/></p>
<p class="paragraph_style_10"><br/></p>
<div class="paragraph paragraph_style_10"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_11.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_10"><br/></p>
<p class="paragraph_style_11"><br/></p>
<p class="paragraph_style_12">wc_AesSetKey<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int wc_AesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv, int dir);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function initializes an AES structure by setting the key and then setting the initialization vector.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully setting key and initialization vector.<br/></p>
<p class="paragraph_style_9"><span class="style_3">BAD_FUNC_ARG</span>: Returned if key length is invalid.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES structure to modify<br/></p>
<p class="paragraph_style_9"><span class="style_3">key</span> - 16, 24, or 32 byte secret key for encryption and decryption<br/></p>
<p class="paragraph_style_9"><span class="style_3">len</span> - length of the key passed in<br/></p>
<p class="paragraph_style_9"><span class="style_3">iv</span> – pointer to the initialization vector used to initialize the key<br/></p>
<p class="paragraph_style_9"><span class="style_3">dir</span> - Cipher direction. Set <span class="style_3">AES_ENCRYPTION</span> to encrypt,  or <span class="style_3">AES_DECRYPTION</span> to decrypt. (See enum in wolfssl/wolfcrypt/aes.h)<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc;<br/></p>
<p class="paragraph_style_14">int ret = 0;<br/></p>
<p class="paragraph_style_14">byte key[] = { /* some 16, 24 or 32 byte key */ };<br/></p>
<p class="paragraph_style_14">byte iv[]  = { /* some 16 byte iv */ };<br/></p>
<p class="paragraph_style_14">if (ret = wc_AesSetKey(&amp;enc, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION) != 0) {<br/></p>
<p class="paragraph_style_14">// failed to set aes key<br/></p>
<p class="paragraph_style_14">}<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesSetKeyDirect, wc_AesSetIV<br/></p>
<p class="paragraph_style_10"><br/></p>
<p class="paragraph_style_10"><br/></p>
<div class="paragraph paragraph_style_10"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_12.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_10"><br/></p>
<p class="paragraph_style_11"><br/></p>
<p class="paragraph_style_12">wc_AesSetIV<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int wc_AesSetIV(Aes* aes, const byte* iv);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function sets the initialization vector for a particular AES object. The AES object should be initialized before calling this function.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully setting initialization vector.<br/></p>
<p class="paragraph_style_9"><span class="style_3">BAD_FUNC_ARG</span>: Returned if AES pointer is NULL.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES structure on which to set the initialization vector<br/></p>
<p class="paragraph_style_9"><span class="style_3">iv</span> - initialization vector used to initialize the AES structure<br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc;<br/></p>
<p class="paragraph_style_14">// set enc key<br/></p>
<p class="paragraph_style_14">byte iv[]  = { /* some 16 byte iv */ };<br/></p>
<p class="paragraph_style_14">if (ret = wc_AesSetIV(&amp;enc, iv) != 0) {<br/></p>
<p class="paragraph_style_14">// failed to set aes iv<br/></p>
<p class="paragraph_style_14">}<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_10">wc_AesSetKeyDirect, wc_AesSetKey<br/></p>
<p class="paragraph_style_10"><br/></p>
<div class="paragraph paragraph_style_10"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_13.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_10"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesCbcEncrypt<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">Encrypts a plaintext message from the input buffer in, and places the resulting cipher text in the output buffer out using cipher block chaining with AES. This function requires that the AES object has been initialized by calling AesSetKey before a message is able to be encrypted.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">This function assumes that the input message is AES block length aligned according to PKCS#7. This differs from the OpenSSL AES-CBC methods which do not require alignment, and instead pad user's input to a full block, or append an extra padding block if the input is already block aligned. <br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">To make the wolfSSL function and equivalent OpenSSL functions interoperate, one should specify the no-pad option in the OpenSSL command line function so that it behaves like the wolfSSL AesCbcEncrypt method and does not add extra padding during encryption.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully encrypting message.<br/></p>
<p class="paragraph_style_9"><span class="style_3">BAD_ALIGN_E</span>: Returned on block align error<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to encrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">out</span> - pointer to the output buffer in which to store the ciphertext of the encrypted message<br/></p>
<p class="paragraph_style_9"><span class="style_3">in</span> - pointer to the input buffer containing message to be encrypted<br/></p>
<p class="paragraph_style_9"><span class="style_3">sz</span> - size of input message<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc;<br/></p>
<p class="paragraph_style_14">int ret = 0;<br/></p>
<p class="paragraph_style_14">// initialize enc with AesSetKey, using direction AES_ENCRYPTION<br/></p>
<p class="paragraph_style_14">byte msg[AES_BLOCK_SIZE * n]; // multiple of 16 bytes<br/></p>
<p class="paragraph_style_14">// fill msg with data<br/></p>
<p class="paragraph_style_14">byte cipher[AES_BLOCK_SIZE * n]; // Some multiple of 16 bytes<br/></p>
<p class="paragraph_style_14">if ((ret = wc_AesCbcEncrypt(&amp;enc, cipher, message, sizeof(msg))) != 0 ) {<br/></p>
<p class="paragraph_style_14">// block align error<br/></p>
<p class="paragraph_style_14">}<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesSetKey, wc_AesSetIV, wc_AesCbcDecrypt<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_14.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesCbcDecrypt<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int  wc_AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">Decrypts a cipher from the input buffer in, and places the resulting plain text in the output buffer out using cipher block chaining with AES. This function requires that the AES structure has been initialized by calling AesSetKey before a message is able to be decrypted.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">This function assumes that the original message was AES block length aligned according to PKCS#7. This differs from the OpenSSL AES-CBC methods which do not require alignment, and instead pad user's input to a full block, or append an extra padding block if the input is already block aligned.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">To make the wolfSSL function and equivalent OpenSSL functions interoperate, one should specify the no-pad option in the OpenSSL command line function so that it behaves like the wolfSSL AesCbcEncrypt method and does not create errors during decryption.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully decrypting message.<br/></p>
<p class="paragraph_style_9"><span class="style_3">BAD_ALIGN_E</span>: Returned on block align error<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to decrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">out</span> - pointer to the output buffer in which to store the plain text of the decrypted message<br/></p>
<p class="paragraph_style_9"><span class="style_3">in</span> - pointer to the input buffer containing cipher text to be decrypted<br/></p>
<p class="paragraph_style_9"><span class="style_3">sz</span> - size of input message<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes dec;<br/></p>
<p class="paragraph_style_14">int ret = 0;<br/></p>
<p class="paragraph_style_14">// initialize dec with AesSetKey, using direction AES_DECRYPTION<br/></p>
<p class="paragraph_style_14">byte cipher[AES_BLOCK_SIZE * n]; // some multiple of 16 bytes<br/></p>
<p class="paragraph_style_14">// fill cipher with cipher text<br/></p>
<p class="paragraph_style_14">byte plain [AES_BLOCK_SIZE * n];<br/></p>
<p class="paragraph_style_14">if ((ret = wc_AesCbcDecrypt(&amp;dec, plain, cipher, sizeof(cipher))) != 0 ) {<br/></p>
<p class="paragraph_style_14">// block align error<br/></p>
<p class="paragraph_style_14">}<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesSetKey, wc_AesCbcEncrypt<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_15.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesCbcDecryptWithKey<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int  wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz, const byte* key, word32 keySz, const byte* iv);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">Decrypts a cipher from the input buffer in, and places the resulting plain text in the output buffer out using cipher block chaining with AES. This function does not require an AES structure to be initialized. Instead, it takes in a key and an iv (initialization vector) and uses these to initialize an AES object and then decrypt the cipher text.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully decrypting message<br/></p>
<p class="paragraph_style_9"><span class="style_3">BAD_ALIGN_E</span>: Returned on block align error<br/></p>
<p class="paragraph_style_9"><span class="style_3">BAD_FUNC_ARG</span>: Returned if key length is invalid or AES object is null during AesSetIV<br/></p>
<p class="paragraph_style_9"><span class="style_3">MEMORY_E</span>: Returned if WOLFSSL_SMALL_STACK is enabled and XMALLOC fails to instantiate an AES object.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">out</span> - pointer to the output buffer in which to store the plain text of the decrypted message<br/></p>
<p class="paragraph_style_9"><span class="style_3">in</span> - pointer to the input buffer containing cipher text to be decrypted<br/></p>
<p class="paragraph_style_9"><span class="style_3">inSz</span> - size of input message<br/></p>
<p class="paragraph_style_9"><span class="style_3">key</span> - 16, 24, or 32 byte secret key for decryption<br/></p>
<p class="paragraph_style_9"><span class="style_3">keySz</span> - size of key used for decryption<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">int ret = 0;<br/></p>
<p class="paragraph_style_14">byte key[] = { /* some 16, 24, or 32 byte key */ };<br/></p>
<p class="paragraph_style_14">byte iv[]  = { /* some 16 byte iv */ };<br/></p>
<p class="paragraph_style_14">byte cipher[AES_BLOCK_SIZE * n]; //n being a positive integer making cipher some multiple of 16 bytes<br/></p>
<p class="paragraph_style_14">// fill cipher with cipher text<br/></p>
<p class="paragraph_style_14">byte plain [AES_BLOCK_SIZE * n];<br/></p>
<p class="paragraph_style_14">if ((ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, AES_BLOCK_SIZE, iv)) != 0 ) {<br/></p>
<p class="paragraph_style_14">// Decrypt Error<br/></p>
<p class="paragraph_style_14">}<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesSetKey, wc_AesSetIV, wc_AesCbcEncrypt, wc_AesCbcDecrypt<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_16.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesCtrEncrypt<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">void wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">Encrypts/Decrypts a message from the input buffer in, and places the resulting cipher text in the output buffer out using CTR mode with AES. This function is only enabled if WOLFSSL_AES_COUNTER is enabled at compile time. The AES structure should be initialized through AesSetKey before calling this function. Note that this function is used for both decryption and encryption.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9">No return value for this function.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to decrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">out</span> - pointer to the output buffer in which to store the cipher text of the encrypted message<br/></p>
<p class="paragraph_style_9"><span class="style_3">in</span> - pointer to the input buffer containing plain text to be encrypted<br/></p>
<p class="paragraph_style_9"><span class="style_3">sz</span> - size of the input plain text<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc_dec;<br/></p>
<p class="paragraph_style_14">// initialize enc_dec with AesSetKeyDirect, using direction AES_ENCRYPTION<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">byte msg[AES_BLOCK_SIZE * n]; //n being a positive integer making msg some multiple of 16 bytes<br/></p>
<p class="paragraph_style_14">// fill plain with message text<br/></p>
<p class="paragraph_style_14">byte cipher[AES_BLOCK_SIZE * n];<br/></p>
<p class="paragraph_style_14">byte decrypted[AES_BLOCK_SIZE * n];<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">wc_AesCtrEncrypt(&amp;enc_dec, cipher, msg, sizeof(msg)); // encrypt plain<br/></p>
<p class="paragraph_style_14">wc_AesCtrEncrypt(&amp;enc_dec, decrypted, cipher, sizeof(cipher)); // decrypt cipher text<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesSetKey<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_17.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesEncryptDirect<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">void wc_AesEncryptDirect(Aes* aes, byte* out, const byte* in)<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function is a one-block encrypt of the input block, in, into the output block, out. It uses the key and iv (initialization vector) of the provided AES structure, which should be initialized with wc_AesSetKey before calling this function. It is only enabled if the configure option WOLFSSL_AES_DIRECT is enabled.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9">No return value for this function.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to encrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">out</span> - pointer to the output buffer in which to store the cipher text of the encrypted message<br/></p>
<p class="paragraph_style_9"><span class="style_3">in</span> - pointer to the input buffer containing plain text to be encrypted<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc;<br/></p>
<p class="paragraph_style_14">// initialize enc with AesSetKey, using direction AES_ENCRYPTION<br/></p>
<p class="paragraph_style_14">byte msg [AES_BLOCK_SIZE]; // 16 bytes<br/></p>
<p class="paragraph_style_14">// initialize msg with plain text to encrypt<br/></p>
<p class="paragraph_style_14">byte cipher[AES_BLOCK_SIZE];<br/></p>
<p class="paragraph_style_14">wc_AesEncryptDirect(&amp;enc, cipher, msg);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesDecryptDirect, wc_AesSetKeyDirect<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_18.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesDecryptDirect<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">void wc_AesDecryptDirect(Aes* aes, byte* out, const byte* in);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function is a one-block decrypt of the input block, in, into the output block, out. It uses the key and iv (initialization vector) of the provided AES structure, which should be initialized with wc_AesSetKey before calling this function. It is only enabled if the configure option WOLFSSL_AES_DIRECT is enabled, and there is support for direct AES encryption on the system in question.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9">No return value for this function.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to encrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">out</span> - pointer to the output buffer in which to store the plain text of the decrypted cipher text<br/></p>
<p class="paragraph_style_9"><span class="style_3">in</span> - pointer to the input buffer containing cipher text to be decrypted<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes dec;<br/></p>
<p class="paragraph_style_14">// initialize enc with AesSetKey, using direction AES_DECRYPTION<br/></p>
<p class="paragraph_style_14">byte cipher [AES_BLOCK_SIZE]; // 16 bytes<br/></p>
<p class="paragraph_style_14">// initialize cipher with cipher text to decrypt<br/></p>
<p class="paragraph_style_14">byte msg[AES_BLOCK_SIZE];<br/></p>
<p class="paragraph_style_14">wc_AesDecryptDirect(&amp;dec, msg, cipher);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesEncryptDirect, wc_AesSetKeyDirect<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_19.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesSetKeyDirect<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int wc_AesSetKeyDirect(Aes* aes, const byte* key, word32 len, const byte* iv, int dir);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function is used to set the AES keys for CTR mode with AES. It initializes an AES object with the given key, iv (initialization vector), and encryption dir (direction). It is only enabled if the configure option WOLFSSL_AES_DIRECT is enabled. Currently wc_AesSetKeyDirect uses wc_AesSetKey internally.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully setting the key.<br/></p>
<p class="paragraph_style_9"><span class="style_3">BAD_FUNC_ARG</span>: Returned if the given key is an invalid length<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to encrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">key</span> - 16, 24, or 32 byte secret key for encryption and decryption<br/></p>
<p class="paragraph_style_9"><span class="style_3">len</span> - length of the key passed in<br/></p>
<p class="paragraph_style_9"><span class="style_3">iv</span> - initialization vector used to initialize the key<br/></p>
<p class="paragraph_style_9"><span class="style_3">dir</span> - Cipher direction. Set AES_ENCRYPTION to encrypt,  or AES_DECRYPTION to decrypt. (See enum in wolfssl/wolfcrypt/aes.h)<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc;<br/></p>
<p class="paragraph_style_14">int ret = 0;<br/></p>
<p class="paragraph_style_14">byte key[] = { /* some 16, 24, or 32 byte key */ };<br/></p>
<p class="paragraph_style_14">byte iv[]  = { /* some 16 byte iv */ };<br/></p>
<p class="paragraph_style_14">if (ret = wc_AesSetKeyDirect(&amp;enc, key, sizeof(key), iv, AES_ENCRYPTION) != 0) {<br/></p>
<p class="paragraph_style_14">// failed to set aes key<br/></p>
<p class="paragraph_style_14">}<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesEncryptDirect, wc_AesDecryptDirect, wc_AesSetKey<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_20.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesGcmSetKey<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function is used to set the key for AES GCM (Galois/Counter Mode). It initializes an AES object with the given key. It is only enabled if the configure option HAVE_AESGCM is enabled at compile time.<br/></p>
<p class="paragraph_style_13"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully setting the key.<br/></p>
<p class="paragraph_style_9"><span class="style_3">BAD_FUNC_ARG</span>: Returned if the given key is an invalid length.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to encrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">key</span> - 16, 24, or 32 byte secret key for encryption and decryption<br/></p>
<p class="paragraph_style_9"><span class="style_3">len</span> - length of the key passed in<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc;<br/></p>
<p class="paragraph_style_14">int ret = 0;<br/></p>
<p class="paragraph_style_14">byte key[] = { /* some 16, 24,32 byte key */ };<br/></p>
<p class="paragraph_style_14">if (ret = wc_AesGcmSetKey(&amp;enc, key, sizeof(key)) != 0) {<br/></p>
<p class="paragraph_style_14">// failed to set aes key<br/></p>
<p class="paragraph_style_14">}<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesGcmEncrypt, wc_AesGcmDecrypt<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_21.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesGcmEncrypt<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int  wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz, const byte* iv,<br/></p>
<p class="paragraph_style_9">word32 ivSz, byte* authTag, word32 authTagSz, const byte* authIn,<br/></p>
<p class="paragraph_style_9">word32 authInSz);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function encrypts the input message, held in the buffer in, and stores the resulting cipher text in the output buffer out. It requires a new iv (initialization vector) for each call to encrypt. It also encodes the input authentication vector, authIn, into the authentication tag, authTag.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully encrypting the input message<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to encrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">out</span> - pointer to the output buffer in which to store the cipher text<br/></p>
<p class="paragraph_style_9"><span class="style_3">in</span> - pointer to the input buffer holding the message to encrypt<br/></p>
<p class="paragraph_style_9"><span class="style_3">sz</span> - length of the input message to decrypt<br/></p>
<p class="paragraph_style_9"><span class="style_3">iv</span> - pointer to the buffer containing the initialization vector<br/></p>
<p class="paragraph_style_9"><span class="style_3">ivSz</span> - length of the initialization vector<br/></p>
<p class="paragraph_style_9"><span class="style_3">authTag</span> - pointer to the buffer in which to store the authentication tag<br/></p>
<p class="paragraph_style_9"><span class="style_3">authTagSz</span> - length of the desired authentication tag<br/></p>
<p class="paragraph_style_9"><span class="style_3">authIn</span> - pointer to the buffer containing the input authentication vector<br/></p>
<p class="paragraph_style_9"><span class="style_3">authInSz</span> - length of the input authentication vector<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc;<br/></p>
<p class="paragraph_style_14">// initialize aes structure by calling wc_AesGcmSetKey<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">byte plain[AES_BLOCK_LENGTH * n]; //n being a positive integer making plain some multiple of 16 bytes<br/></p>
<p class="paragraph_style_14">// initialize plain with msg to encrypt<br/></p>
<p class="paragraph_style_14">byte cipher[sizeof(plain)];<br/></p>
<p class="paragraph_style_14">byte iv[] = // some 16 byte iv<br/></p>
<p class="paragraph_style_14">byte authTag[AUTH_TAG_LENGTH];<br/></p>
<p class="paragraph_style_14">byte authIn[] = // Authentication Vector<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">wc_AesGcmEncrypt(&amp;enc, cipher, plain, sizeof(cipher), iv, sizeof(iv),<br/></p>
<p class="paragraph_style_14">authTag, sizeof(authTag), authIn, sizeof(authIn));<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesGcmSetKey, wc_AesGcmDecrypt<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_22.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesGcmDecrypt<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int  wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, const byte* iv,<br/></p>
<p class="paragraph_style_9">word32 ivSz, const byte* authTag, word32 authTagSz, const byte* authIn, word32 authInSz);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function decrypts the input cipher text, held in the buffer in, and stores the resulting message text in the output buffer out. It also checks the input authentication vector, authIn, against the supplied authentication tag, authTag.  <br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully decrypting the input message<br/></p>
<p class="paragraph_style_9"><span class="style_3">AES_GCM_AUTH_E</span>: If the authentication tag does not match the supplied authentication code vector, authTag.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to encrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">out</span> - pointer to the output buffer in which to store the message text<br/></p>
<p class="paragraph_style_9"><span class="style_3">in</span> - pointer to the input buffer holding the cipher text to decrypt<br/></p>
<p class="paragraph_style_9"><span class="style_3">sz</span> - length of the cipher text to decrypt<br/></p>
<p class="paragraph_style_9"><span class="style_3">iv</span> - pointer to the buffer containing the initialization vector<br/></p>
<p class="paragraph_style_9"><span class="style_3">ivSz</span> - length of the initialization vector<br/></p>
<p class="paragraph_style_9"><span class="style_3">authTag</span> - pointer to the buffer containing the authentication tag<br/></p>
<p class="paragraph_style_9"><span class="style_3">authTagSz</span> - length of the desired authentication tag<br/></p>
<p class="paragraph_style_9"><span class="style_3">authIn</span> - pointer to the buffer containing the input authentication vector<br/></p>
<p class="paragraph_style_9"><span class="style_3">authInSz</span> - length of the input authentication vector<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes dec;<br/></p>
<p class="paragraph_style_14">// initialize aes structure by calling wc_AesGcmSetKey<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">byte cipher[AES_BLOCK_LENGTH * n]; //n being a positive integer making cipher some multiple of 16 bytes<br/></p>
<p class="paragraph_style_14">// initialize cipher with cipher text to decrypt<br/></p>
<p class="paragraph_style_14">byte plain[sizeof(cipher)];<br/></p>
<p class="paragraph_style_14">byte iv[] = // some 16 byte iv<br/></p>
<p class="paragraph_style_14">byte authTag[AUTH_TAG_LENGTH];<br/></p>
<p class="paragraph_style_14">byte authIn[] = // Authentication Vector<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">wc_AesGcmEncrypt(&amp;enc, cipher, plain, sizeof(cipher), iv, sizeof(iv),<br/></p>
<p class="paragraph_style_14">authTag, sizeof(authTag), authIn, sizeof(authIn));<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesGcmSetKey, wc_AesGcmEncrypt<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_23.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_GmacSetKey<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int wc_GmacSetKey(Gmac* gmac, const byte* key, word32 len);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function sets the key for a GMAC object to be used for Galois Message Authentication.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully setting the key<br/></p>
<p class="paragraph_style_9"><span class="style_3">BAD_FUNC_ARG</span>: Returned if key length is invalid.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">gmac</span> - pointer to the gmac object used for authentication<br/></p>
<p class="paragraph_style_9"><span class="style_3">key</span> - 16, 24, or 32 byte secret key for authentication<br/></p>
<p class="paragraph_style_9"><span class="style_3">len</span> - length of the key<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Gmac gmac;<br/></p>
<p class="paragraph_style_14">key[] = { /* some 16, 24, or 32 byte length key */ };<br/></p>
<p class="paragraph_style_14">wc_GmacSetKey(&amp;gmac, key, sizeof(key));<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_GmacUpdate<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_24.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_GmacUpdate<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int wc_GmacUpdate(Gmac* gmac, const byte* iv, word32 ivSz, const byte* authIn,<br/></p>
<p class="paragraph_style_9">word32 authInSz, byte* authTag, word32 authTagSz)<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function generates the Gmac hash of the authIn input and stores the result in the authTag buffer. After running wc_GmacUpdate, one should compare the generated authTag to a known authentication tag to verify the authenticity of a message.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully computing the Gmac hash.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">gmac</span> - pointer to the gmac object used for authentication<br/></p>
<p class="paragraph_style_9"><span class="style_3">iv</span> - initialization vector used for the hash<br/></p>
<p class="paragraph_style_9"><span class="style_3">ivSz</span> - size of the initialization vector used<br/></p>
<p class="paragraph_style_9"><span class="style_3">authIn</span> - pointer to the buffer containing the authentication vector to verify<br/></p>
<p class="paragraph_style_9"><span class="style_3">authInSz</span> - size of the authentication vector<br/></p>
<p class="paragraph_style_9"><span class="style_3">authTag</span> - pointer to the output buffer in which to store the Gmac hash<br/></p>
<p class="paragraph_style_9"><span class="style_3">authTagSz</span> - the size of the output buffer used to store the Gmac hash<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Gmac gmac;<br/></p>
<p class="paragraph_style_14">key[] = { /* some 16, 24, or 32 byte length key */ };<br/></p>
<p class="paragraph_style_14">iv[] = { /* some 16 byte length iv */ };<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">wc_GmacSetKey(&amp;gmac, key, sizeof(key));<br/></p>
<p class="paragraph_style_14">authIn[] = { /* some 16 byte authentication input */ };<br/></p>
<p class="paragraph_style_14">tag[AES_BLOCK_SIZE]; // will store authentication code<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">wc_GmacUpdate(&amp;gmac, iv, sizeof(iv), authIn, sizeof(authIn), tag, sizeof(tag));<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_GmacSetKey<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_25.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesCcmSetKey<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">void wc_AesCcmSetKey(Aes* aes, const byte* key, word32 keySz);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function sets the key for an AES object using CCM (Counter with CBC-MAC). It takes a pointer to an AES structure and initializes it with supplied key.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9">No return value for this function.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - aes structure in which to store the supplied key<br/></p>
<p class="paragraph_style_9"><span class="style_3">key</span> - 16, 24, or 32 byte secret key for encryption and decryption<br/></p>
<p class="paragraph_style_9"><span class="style_3">keySz</span> - size of the supplied key<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc;<br/></p>
<p class="paragraph_style_14">key[] = { /* some 16, 24, or 32 byte length key */ };<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">wc_AesCcmSetKey(&amp;aes, key, sizeof(key));<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesCcmEncrypt, wc_AesCcmDecrypt<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_26.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesCcmEncrypt<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">void wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, const byte* nonce, <br/></p>
<p class="paragraph_style_9">                                        word32 nonceSz, byte* authTag, word32 authTagSz, byte* authIn,<br/></p>
<p class="paragraph_style_9">                  word32 authInSz);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function encrypts the input message, in, into the output buffer, out, using CCM (Counter with CBC-MAC). It subsequently calculates and stores the authorization tag, authTag, from the authIn input.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9">No return value for this function.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to encrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">out</span> - pointer to the output buffer in which to store the cipher text<br/></p>
<p class="paragraph_style_9"><span class="style_3">in</span> - pointer to the input buffer holding the message to encrypt<br/></p>
<p class="paragraph_style_9"><span class="style_3">sz</span> - length of the input message to encrypt<br/></p>
<p class="paragraph_style_9"><span class="style_3">nonce</span> - pointer to the buffer containing the nonce (number only used once)<br/></p>
<p class="paragraph_style_9"><span class="style_3">nonceSz</span> - length of the nonce<br/></p>
<p class="paragraph_style_9"><span class="style_3">authTag</span> - pointer to the buffer in which to store the authentication tag<br/></p>
<p class="paragraph_style_9"><span class="style_3">authTagSz</span> - length of the desired authentication tag<br/></p>
<p class="paragraph_style_9"><span class="style_3">authIn</span> - pointer to the buffer containing the input authentication vector<br/></p>
<p class="paragraph_style_9"><span class="style_3">authInSz</span> - length of the input authentication vector<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc;<br/></p>
<p class="paragraph_style_14">// initialize enc with wc_AesCcmSetKey<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">nonce[] = { /* initialize nonce */ };<br/></p>
<p class="paragraph_style_14">plain[] = { /* some plain text message */ };<br/></p>
<p class="paragraph_style_14">cipher[sizeof(plain)];<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">authIn[] = { /* some 16 byte authentication input */ };<br/></p>
<p class="paragraph_style_14">tag[AES_BLOCK_SIZE]; // will store authentication code<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">wc_AesCcmEncrypt(&amp;enc, cipher, plain, sizeof(plain), nonce, sizeof(nonce),<br/></p>
<p class="paragraph_style_14">tag, sizeof(tag), authIn, sizeof(authIn));<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesCcmSetKey, wc_AesCcmDecrypt<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_27.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesCcmDecrypt<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int  wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, const byte* nonce, <br/></p>
<p class="paragraph_style_9">                                        word32 nonceSz, const byte* authTag, word32 authTagSz,<br/></p>
<p class="paragraph_style_9">                                        const byte* authIn, word32 authInSz)<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function decrypts the input cipher text, in, into the output buffer, out, using CCM (Counter with CBC-MAC). It subsequently calculates the authorization tag, authTag, from the authIn input. If the authorization tag is invalid, it sets the output buffer to zero and returns the error: AES_CCM_AUTH_E.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully decrypting the input message<br/></p>
<p class="paragraph_style_9"><span class="style_3">AES_CCM_AUTH_E</span>: If the authentication tag does not match the supplied authentication code vector, authTag.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to encrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">out</span> - pointer to the output buffer in which to store the cipher text<br/></p>
<p class="paragraph_style_9"><span class="style_3">in</span> - pointer to the input buffer holding the message to encrypt<br/></p>
<p class="paragraph_style_9"><span class="style_3">sz</span> - length of the input cipher text to decrypt<br/></p>
<p class="paragraph_style_9"><span class="style_3">nonce</span> - pointer to the buffer containing the nonce (number only used once)<br/></p>
<p class="paragraph_style_9"><span class="style_3">nonceSz</span> - length of the nonce<br/></p>
<p class="paragraph_style_9"><span class="style_3">authTag</span> - pointer to the buffer in which to store the authentication tag<br/></p>
<p class="paragraph_style_9"><span class="style_3">authTagSz</span> - length of the desired authentication tag<br/></p>
<p class="paragraph_style_9"><span class="style_3">authIn</span> - pointer to the buffer containing the input authentication vector<br/></p>
<p class="paragraph_style_9"><span class="style_3">authInSz</span> - length of the input authentication vector<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes dec;<br/></p>
<p class="paragraph_style_14">// initialize dec with wc_AesCcmSetKey<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">nonce[] = { /* initialize nonce */ };<br/></p>
<p class="paragraph_style_14">cipher[] = { /* encrypted message */ };<br/></p>
<p class="paragraph_style_14">plain[sizeof(cipher)];<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">authIn[] = { /* some 16 byte authentication input */ };<br/></p>
<p class="paragraph_style_14">tag[AES_BLOCK_SIZE] = { /* authentication tag received for verification */ };<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">int return = wc_AesCcmDecrypt(&amp;dec, plain, cipher, sizeof(cipher), nonce, sizeof(nonce),tag, sizeof(tag), authIn, sizeof(authIn));<br/></p>
<p class="paragraph_style_14">if(return != 0) {<br/></p>
<p class="paragraph_style_14">// decrypt error, invalid authentication code<br/></p>
<p class="paragraph_style_14">}<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesCcmSetKey, wc_AesCcmEncrypt<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_28.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesInitCavium<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">int wc_AesInitCavium(Aes* aes, int devId)<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function initializes AES for use with Cavium Nitrox devices. It should be called  before wc_AesSetKey when using Cavium hardware cryptography.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9"><span class="style_3">0</span>: On successfully initializing cavium.<br/></p>
<p class="paragraph_style_9"><span class="style_3">-1</span>: Returned if the AES structure is NULL, or the call to CspAllocContext fails.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES object used to encrypt data<br/></p>
<p class="paragraph_style_9"><span class="style_3">devId</span> - Nitrox device id<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc;<br/></p>
<p class="paragraph_style_14">wc_AesInitCavium(&amp;aes, CAVIUM_DEV_ID);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesFreeCavium<br/></p>
<p class="paragraph_style_9"><br/></p>
<div class="paragraph paragraph_style_9"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_29.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_12"><br/></p>
<p class="paragraph_style_12">wc_AesFreeCavium<br/></p>
<p class="paragraph_style_13">Synopsis:<br/></p>
<p class="paragraph_style_9">#include &lt;wolfssl/wolfcrypt/aes.h&gt;<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_9">void wc_AesFreeCavium(Aes* aes)<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Description:<br/></p>
<p class="paragraph_style_9">This function frees the AES structure used with Cavium Nitrox devices.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Return Values:<br/></p>
<p class="paragraph_style_9">No return value for this function.<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Parameters:<br/></p>
<p class="paragraph_style_9"><span class="style_3">aes</span> - pointer to the AES structure to free<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">Example:<br/></p>
<p class="paragraph_style_14">Aes enc;<br/></p>
<p class="paragraph_style_14">... // initialize Cavium, perform encryption<br/></p>
<p class="paragraph_style_14"><br/></p>
<p class="paragraph_style_14">wc_AesFreeCavium(&amp;aes);<br/></p>
<p class="paragraph_style_9"><br/></p>
<p class="paragraph_style_13">See Also:<br/></p>
<p class="paragraph_style_9">wc_AesInit_Cavium<br/></p>
<p class="paragraph_style_10"><br/></p>
<div class="paragraph paragraph_style_10"><div style="height: 1px; width: 693px;  height: 1px; left: 0px; position: relative; top: 1px; width: 693px; " class="tinyText inline-block"><div style="position: relative; width: 693px; "><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_30.jpg" alt="" style="height: 1px; left: 0px; position: absolute; top: 0px; width: 693px; "/></div></div><br/></div>
</div>
<div style="clear: both; height: 0px; line-height: 0px; " class="tinyText"> </div>
</div>
</div>
<div style="height: 16px; width: 20px;  height: 16px; left: 706px; position: absolute; top: 51px; width: 20px; z-index: 1; " class="tinyText">
<div style="position: relative; width: 20px; ">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/shapeimage_31.png" alt="" style="height: 16px; left: 0px; position: absolute; top: 0px; width: 20px; "/>
</div>
</div>
<div style="height: 19px; width: 19px;  height: 19px; left: 707px; position: absolute; top: 25px; width: 19px; z-index: 1; " class="tinyText style_SkipStroke_2">
<img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/United%20Kingdom(Great%20Britain).png" alt="" style="border: none; height: 19px; width: 19px; "/>
</div>
<div id="id16" style="height: 23px; left: 328px; position: absolute; top: 48px; width: 258px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_258_23" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_15">Questions? +1 (425) 245-8247</p>
</div>
</div>
</div>
<div style="height: 19px; width: 19px;  height: 19px; left: 685px; position: absolute; top: 25px; width: 19px; z-index: 1; " class="tinyText style_SkipStroke_2">
<a href="http://www.wolfssl.jp/" title="http://www.wolfssl.jp"><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/japan.png" alt="" style="border: none; height: 19px; width: 19px; "/></a>
</div>
<div id="id17" style="height: 28px; left: 593px; position: absolute; top: 44px; width: 119px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_119_28" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_16"><a class="class13" title="https://www.wolfssl.com/forums" href="https://www.wolfssl.com/forums">Support <span class="style_4">Forums</span></a></p>
</div>
</div>
</div>
<div id="id18" style="height: 27px; left: 59px; position: absolute; top: 190px; width: 342px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_342_27" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_17"><a class="class14" title="https://www.wolfssl.com/documentation/wolfSSL-Manual.pdf" href="https://www.wolfssl.com/documentation/wolfSSL-Manual.pdf">Download wolfSSL Manual (PDF)</a></p>
</div>
</div>
</div>
<div style="height: 121px; width: 155px;  height: 121px; left: 32px; position: absolute; top: 5px; width: 155px; z-index: 1; " class="tinyText style_SkipStroke_2">
<a href="Home.html" title="Home.html"><img src="Docs-wolfssl-manual-18-1-wolfcrypt-api-aes_files/wolfssl_logo.png" alt="" style="border: none; height: 121px; width: 156px; "/></a>
</div>
<div style="height: 10393px; line-height: 10393px; " class="spacer"> </div>
</div>
<div style="height: 100px; margin-left: 0px; position: relative; width: 770px; z-index: 15; " id="footer_layer">
<div style="height: 0px; line-height: 0px; " class="bumper"> </div>
<div id="id19" style="height: 27px; left: 634px; position: absolute; top: 27px; width: 102px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_102_27" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_4"><a class="class15" title="Docs-wolfssl-manual-18-2-wolfcrypt-api-arc4.html" href="Docs-wolfssl-manual-18-2-wolfcrypt-api-arc4.html">Next Chapter</a></p>
</div>
</div>
</div>
<div id="id20" style="height: 25px; left: 35px; position: absolute; top: 27px; width: 125px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_125_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_18"><a class="class16" title="Docs-wolfssl-manual-18-wolfcrypt-api-reference.html" href="Docs-wolfssl-manual-18-wolfcrypt-api-reference.html">Previous Chapter</a></p>
</div>
</div>
</div>
<div id="id21" style="height: 25px; left: 323px; position: absolute; top: 27px; width: 125px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_125_25" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_6"><a class="class17" title="Docs-wolfssl-manual-toc.html" href="Docs-wolfssl-manual-toc.html">Table of Contents</a></p>
</div>
</div>
</div>
<div id="id22" style="height: 29px; left: 35px; position: absolute; top: 65px; width: 701px; z-index: 1; " class="style_SkipStroke shape-with-text">
<div class="text-content graphic_textbox_layout_style_default_External_701_29" style="padding: 0px; ">
<div class="graphic_textbox_layout_style_default">
<p style="padding-bottom: 0pt; padding-top: 0pt; " class="paragraph_style_19">Copyright 2017 wolfSSL Inc.  All rights reserved.</p>
</div>
</div>
</div>
</div>
</div>
</div>
 </body>

<!-- Mirrored from www.wolfssl.com/wolfSSL/Docs-wolfssl-manual-18-1-wolfcrypt-api-aes.html by HTTrack Website Copier/3.x [XR&CO'2014], Tue, 17 Jan 2017 13:36:48 GMT -->
</html>
